package com.example.ktpspringboot.service.impl;

import com.example.ktpspringboot.entity.HomeWork;
import com.example.ktpspringboot.mapper.CourseMapper;
import com.example.ktpspringboot.mapper.HomeWorkMapper;
import com.example.ktpspringboot.service.HomeWorkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HomeWorkServiceImpl implements HomeWorkService {

    @Autowired
    private HomeWorkMapper homeWorkMapper;

    @Autowired
    private CourseMapper courseMapper;

    @Autowired
    private CourseServiceImpl courseServiceImpl;
    String judgePhone = "^\\d{11}$";
    String judgeEmail = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)+$";
    String judgeAccount = "^ktp\\d{10}$";

    @Override
    public String workFormat(int workFormat, String restrictFormat) {
        switch (workFormat) {
            case 3:
                return "所有格式(支持文档、图片、音视频等共80种格式)";
            case 6:
                return "查看文档格式(支持doc、docx、pdf格式，系统可以对学生提交的作业自动查重)";
            case 9:
                return "限制学生文档格式(指定学生的文档提交格式) 限制的格式为：" + restrictFormat;
        }
        return null;
    }

    @Override
    public String insertHomework(HomeWork homeWork, String code) {
        int total = homeWorkMapper.insertHomeWork(homeWork);
        if (total > 0) {
            int i = homeWorkMapper.insertCourseAndHomeWork(code, homeWork.getUuid());
            if (i > 0) {
                return "创建作业成功";
            }
        } else {
            return "创建作业失败，数据库作业表没有变化";
        }
        return null;
    }

    @Override
    public List<HomeWork> getHomeWork(String code) {
        return homeWorkMapper.getHomeWorkByCode(code);
    }

}
